home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / PROSENV.C < prev    next >
C/C++ Source or Header  |  1991-10-29  |  8KB  |  233 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/users/jinx/microcode/RCS/prosenv.c,v 1.5 1991/10/29 22:55:11 jinx Exp $
  4.  
  5. Copyright (c) 1987-91 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* Process-environment primitives. */
  36.  
  37. #include "scheme.h"
  38. #include "prims.h"
  39. #include "osenv.h"
  40. #include "ostop.h"
  41.  
  42. DEFINE_PRIMITIVE ("GET-DECODED-TIME", Prim_get_decoded_time, 1, 1,
  43.   "Return a vector with the current decoded time;\n\
  44. arg TAG is used to tag the vector.\n\
  45. The vector's elements are:\n\
  46.   #(TAG second minute hour day month year day-of-week)")
  47. {
  48.   struct time_structure ts;
  49.   PRIMITIVE_HEADER (1);
  50.   OS_current_time (&ts);
  51.   {
  52.     SCHEME_OBJECT result = (allocate_marked_vector (TC_VECTOR, 8, 1));
  53.     FAST_VECTOR_SET (result, 0, (ARG_REF (1)));
  54.     FAST_VECTOR_SET (result, 1, (long_to_integer (ts . second)));
  55.     FAST_VECTOR_SET (result, 2, (long_to_integer (ts . minute)));
  56.     FAST_VECTOR_SET (result, 3, (long_to_integer (ts . hour)));
  57.     FAST_VECTOR_SET (result, 4, (long_to_integer (ts . day)));
  58.     FAST_VECTOR_SET (result, 5, (long_to_integer (ts . month)));
  59.     FAST_VECTOR_SET (result, 6, (long_to_integer (ts . year)));
  60.     FAST_VECTOR_SET (result, 7, (long_to_integer (ts . day_of_week)));
  61.     PRIMITIVE_RETURN (result);
  62.   }
  63. }
  64.  
  65. DEFINE_PRIMITIVE ("CURRENT-YEAR", Prim_current_year, 0, 0,
  66.   "This is an obsolete primitive; use `get-decoded-time' instead.")
  67. {
  68.   struct time_structure ts;
  69.   PRIMITIVE_HEADER (0);
  70.   OS_current_time (&ts);
  71.   PRIMITIVE_RETURN (long_to_integer ((ts . year) - 1900));
  72. }
  73.  
  74. #define DATE_PRIMITIVE(element)                        \
  75. {                                    \
  76.   struct time_structure ts;                        \
  77.   PRIMITIVE_HEADER (0);                            \
  78.   OS_current_time (&ts);                        \
  79.   PRIMITIVE_RETURN (long_to_integer (ts . element));            \
  80. }
  81.  
  82. DEFINE_PRIMITIVE ("CURRENT-MONTH", Prim_current_month, 0, 0,
  83.   "This is an obsolete primitive; use `get-decoded-time' instead.")
  84.      DATE_PRIMITIVE (month)
  85.  
  86. DEFINE_PRIMITIVE ("CURRENT-DAY", Prim_current_day, 0, 0,
  87.   "This is an obsolete primitive; use `get-decoded-time' instead.")
  88.      DATE_PRIMITIVE (day)
  89.  
  90. DEFINE_PRIMITIVE ("CURRENT-HOUR", Prim_current_hour, 0, 0,
  91.   "This is an obsolete primitive; use `get-decoded-time' instead.")
  92.      DATE_PRIMITIVE (hour)
  93.  
  94. DEFINE_PRIMITIVE ("CURRENT-MINUTE", Prim_current_minute, 0, 0,
  95.   "This is an obsolete primitive; use `get-decoded-time' instead.")
  96.      DATE_PRIMITIVE (minute)
  97.  
  98. DEFINE_PRIMITIVE ("CURRENT-SECOND", Prim_current_second, 0, 0,
  99.   "This is an obsolete primitive; use `get-decoded-time' instead.")
  100.      DATE_PRIMITIVE (second)
  101.  
  102. DEFINE_PRIMITIVE ("SYSTEM-CLOCK", Prim_system_clock, 0, 0,
  103.   "Return the current process time in units of milliseconds.")
  104. {
  105.   PRIMITIVE_HEADER (0);
  106.   PRIMITIVE_RETURN (long_to_integer (OS_process_clock ()));
  107. }
  108.  
  109. DEFINE_PRIMITIVE ("REAL-TIME-CLOCK", Prim_real_time_clock, 0, 0,
  110.   "Return the current real time in units of milliseconds.")
  111. {
  112.   PRIMITIVE_HEADER (0);
  113.   PRIMITIVE_RETURN (long_to_integer (OS_real_time_clock ()));
  114. }
  115.  
  116. DEFINE_PRIMITIVE ("PROCESS-TIMER-CLEAR", Prim_process_timer_clear, 0, 0,
  117.   "Turn off the process timer.")
  118. {
  119.   PRIMITIVE_HEADER (0);
  120.   OS_process_timer_clear ();
  121.   PRIMITIVE_RETURN (UNSPECIFIC);
  122. }
  123.  
  124. DEFINE_PRIMITIVE ("PROCESS-TIMER-SET", Prim_process_timer_set, 2, 2,
  125.   "Set the process timer.\n\
  126. First arg FIRST says how long to wait until the first interrupt;\n\
  127. second arg INTERVAL says how long to wait between interrupts after that.\n\
  128. Both arguments are in units of milliseconds.")
  129. {
  130.   PRIMITIVE_HEADER (2);
  131.   OS_process_timer_set ((arg_nonnegative_integer (1)),
  132.             (arg_nonnegative_integer (2)));
  133.   PRIMITIVE_RETURN (UNSPECIFIC);
  134. }
  135.  
  136. DEFINE_PRIMITIVE ("REAL-TIMER-CLEAR", Prim_real_timer_clear, 0, 0,
  137.   "Turn off the real timer.")
  138. {
  139.   PRIMITIVE_HEADER (0);
  140.   OS_real_timer_clear ();
  141.   PRIMITIVE_RETURN (UNSPECIFIC);
  142. }
  143.  
  144. DEFINE_PRIMITIVE ("REAL-TIMER-SET", Prim_real_timer_set, 2, 2,
  145.   "Set the real timer.\n\
  146. First arg FIRST says how long to wait until the first interrupt;\n\
  147. second arg INTERVAL says how long to wait between interrupts after that.\n\
  148. Both arguments are in units of milliseconds.")
  149. {
  150.   PRIMITIVE_HEADER (2);
  151.   OS_real_timer_set ((arg_nonnegative_integer (1)),
  152.              (arg_nonnegative_integer (2)));
  153.   PRIMITIVE_RETURN (UNSPECIFIC);
  154. }
  155.  
  156. DEFINE_PRIMITIVE ("SETUP-TIMER-INTERRUPT", Prim_setup_timer_interrupt, 2, 2,
  157.   "This is an obsolete primitive; use `process-timer-set' instead.")
  158. {
  159.   PRIMITIVE_HEADER (2);
  160.   if (((ARG_REF (1)) == SHARP_F) && ((ARG_REF (2)) == SHARP_F))
  161.     OS_process_timer_clear ();
  162.   else
  163.     {
  164.       unsigned long days = (arg_nonnegative_integer (1));
  165.       unsigned long centisec = (arg_nonnegative_integer (2));
  166.       OS_process_timer_set
  167.     ((((days * 24 * 60 * 60 * 100) + centisec) * 10), 0);
  168.     }
  169.   PRIMITIVE_RETURN (UNSPECIFIC);
  170. }
  171.  
  172. DEFINE_PRIMITIVE ("WORKING-DIRECTORY-PATHNAME", Prim_working_dir_pathname, 0, 0,
  173.   "Return the current working directory as a string.")
  174. {
  175.   PRIMITIVE_HEADER (0);
  176.   PRIMITIVE_RETURN (char_pointer_to_string
  177.             ((unsigned char *) OS_working_dir_pathname ()));
  178. }
  179.  
  180. DEFINE_PRIMITIVE ("SET-WORKING-DIRECTORY-PATHNAME!", Prim_set_working_dir_pathname, 1, 1,
  181.   "Change the current working directory to NAME.")
  182. {
  183.   PRIMITIVE_HEADER (1);
  184.   OS_set_working_dir_pathname (STRING_ARG (1));
  185.   PRIMITIVE_RETURN (UNSPECIFIC);
  186. }
  187.  
  188. DEFINE_PRIMITIVE ("GET-ENVIRONMENT-VARIABLE", Prim_get_environment_variable, 1, 1,
  189.   "Look up the value of a variable in the user's shell environment.\n\
  190. The argument, a variable name, must be a string.\n\
  191. The result is either a string (the variable's value),\n\
  192.  or #F indicating that the variable does not exist.")
  193. {
  194.   PRIMITIVE_HEADER (1);
  195.   {
  196.     CONST char * variable_value =
  197.       (OS_get_environment_variable (STRING_ARG (1)));
  198.     PRIMITIVE_RETURN
  199.       ((variable_value == 0)
  200.        ? SHARP_F
  201.        : (char_pointer_to_string ((unsigned char *) variable_value)));
  202.   }
  203. }
  204.  
  205. DEFINE_PRIMITIVE ("CURRENT-USER-NAME", Prim_current_user_name, 0, 0,
  206.   "Return (as a string) the user name of the user running Scheme.")
  207. {
  208.   PRIMITIVE_HEADER (0);
  209.   PRIMITIVE_RETURN (char_pointer_to_string
  210.             ((unsigned char *) OS_current_user_name ()));
  211. }
  212.  
  213. DEFINE_PRIMITIVE ("CURRENT-USER-HOME-DIRECTORY", Prim_current_user_home_directory, 0, 0,
  214.   "Return the name of the current user's home directory.")
  215. {
  216.   PRIMITIVE_HEADER (0);
  217.   PRIMITIVE_RETURN
  218.     (char_pointer_to_string ((unsigned char *)
  219.                  OS_current_user_home_directory ()));
  220. }
  221.  
  222. DEFINE_PRIMITIVE ("SYSTEM-CALL-ERROR-MESSAGE", Prim_system_call_error_message, 1, 1, 0)
  223. {
  224.   PRIMITIVE_HEADER (1);
  225.   {
  226.     CONST char * message =
  227.       (OS_error_code_to_message (arg_nonnegative_integer (1)));
  228.     PRIMITIVE_RETURN
  229.       ((message == 0) ? SHARP_F
  230.        : (char_pointer_to_string ((unsigned char *) message)));
  231.   }
  232. }
  233.